import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";
import _isFunction from "lodash/isFunction";

var _dec, _dec2, _class;

import React from 'react';
import classNames from 'classnames';
import { Bind } from 'lodash-decorators';
import { Tooltip } from 'antd';
import { MenuContext, openMenu, renderMenuTitle } from "./utils";
import styles from "./styles.less?modules";
var SubMenuItem = (_dec = Bind(), _dec2 = Bind(), (_class = /*#__PURE__*/function (_React$PureComponent) {
  _inherits(SubMenuItem, _React$PureComponent);

  var _super = _createSuper(SubMenuItem);

  function SubMenuItem() {
    _classCallCheck(this, SubMenuItem);

    return _super.apply(this, arguments);
  }

  _createClass(SubMenuItem, [{
    key: "handleSubMenuClick",
    value:
    /**
     * 当前节点 只有二级菜单
     */
    function handleSubMenuClick(e) {
      e.preventDefault();
      e.stopPropagation();
      var _this$props = this.props,
          onClick = _this$props.onClick,
          subMenu = _this$props.subMenu;

      var _subMenu$children = _slicedToArray(subMenu.children, 1),
          leafMenu = _subMenu$children[0]; // TODO: 直接在 LeafMenu 处理点击事件
      // 打开菜单


      openMenu(leafMenu);

      if (_isFunction(onClick)) {
        onClick(leafMenu, subMenu);
      }
    }
  }, {
    key: "renderSubMenuItemTitle",
    value: function renderSubMenuItemTitle() {
      var subMenu = this.props.subMenu;
      return renderMenuTitle(subMenu);
    }
  }, {
    key: "render",
    value: function render() {
      var _classNames;

      var _this$props2 = this.props,
          active = _this$props2.active,
          hover = _this$props2.hover,
          style = _this$props2.style,
          subMenu = _this$props2.subMenu;
      var isOnlySubMenu = subMenu.isOnlySubMenu;
      var item = /*#__PURE__*/React.createElement("div", {
        className: classNames(styles['sub-menu-item'], (_classNames = {}, _defineProperty(_classNames, styles['sub-menu-item-active'], active), _defineProperty(_classNames, styles['sub-menu-item-hover'], hover), _defineProperty(_classNames, 'cpaas-sub-menu-item-active', active), _defineProperty(_classNames, 'cpaas-sub-menu-item-hover', hover), _classNames), 'cpaas-sub-menu-item'),
        style: isOnlySubMenu ? _objectSpread(_objectSpread({}, style), {}, {
          cursor: 'pointer'
        }) : style,
        onClick: isOnlySubMenu ? this.handleSubMenuClick : undefined
      }, /*#__PURE__*/React.createElement("div", {
        className: classNames(styles['sub-menu-item-content'], _defineProperty({}, styles['sub-menu-item-content-only'], isOnlySubMenu), 'cpaas-sub-menu-item-content')
      }, /*#__PURE__*/React.createElement("div", {
        className: classNames(styles['sub-menu-item-title'], 'cpaas-sub-menu-item-title')
      }, /*#__PURE__*/React.createElement(MenuContext.Consumer, null, this.renderSubMenuItemTitle))));
      return isOnlySubMenu ? /*#__PURE__*/React.createElement(Tooltip, {
        overlayClassName: styles['menu-tooltip'],
        title: /*#__PURE__*/React.createElement(MenuContext.Consumer, null, this.renderSubMenuItemTitle)
      }, item) : item;
    }
  }]);

  return SubMenuItem;
}(React.PureComponent), (_applyDecoratedDescriptor(_class.prototype, "handleSubMenuClick", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "handleSubMenuClick"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "renderSubMenuItemTitle", [_dec2], Object.getOwnPropertyDescriptor(_class.prototype, "renderSubMenuItemTitle"), _class.prototype)), _class));
export default SubMenuItem;